import os, sys

def file_name(file_dir):
    for root, dirs, files in os.walk(file_dir):
        print("-----------")
        print(root)   #os.walk()所在目录
        print(dirs)   #os.walk()所在目录的所有目录名
        print(files)   #os.walk()所在目录的所有非目录文件名
        print(" ")
        return files


def run():
    data1=read('D:\\大二下\\数据科学\\带作业\\抖音数据\\抖音数据\\all.csv')
    data2=read('D:\\大二下\\数据科学\\带作业\\抖音数据\\抖音数据\\all76.csv')
    data3=[]
    root='D:\\大二下\\数据科学\\带作业\\'
    os.chdir(root+'all')
    all1=file_name(root+'all')
    all2=file_name(root+'all2')
    oldnames=[]
    for i in range(all1.__len__()):
        temp1=all1[i].split('.')
        temp2=temp1[0].split('_')
        oldnames.append([1,i,int(temp2[1])])
    for i in range(all2.__len__()):
        temp1=all2[i].split('.')
        temp2=temp1[0].split('_')
        oldnames.append([2,i,int(temp2[1])])

    for i in range(oldnames.__len__()-1):
        for j in range(i+1,oldnames.__len__()):
            if oldnames[i][2]>oldnames[j][2]:
                temp=oldnames[i]
                oldnames[i]=oldnames[j]
                oldnames[j]=temp
    print(oldnames)

    for i in range(oldnames.__len__()):
        if oldnames[i][0]==1:
            pass
        else:
            pass
def read(path):
    with open(path,'r',encoding='utf-8') as f:
        data=f.read()
        data=data.split('\n')
        for i in range(data.__len__()):
            data[i]=data[i].split(',')
    data.pop(0)
    return data
def write(thePath,data,dim=2,gap=','):
    '''

    :param thePath:
    :param data:二维数组
    :return:
    '''
    if dim==2:
        with open(thePath, 'w', encoding='utf-8') as f:
            length=data.__len__()
            for i in range(length):
                line=[str(x) for x in data[i]]
                f.writelines(gap.join(line))
                if i!=length-1:
                    f.writelines("\n")
    if dim==1:
        with open(thePath, 'w', encoding='utf-8') as f:
            data=[str(x) for x in data]
            f.writelines(gap.join(data))
    return True

def read2(path):
    with open(path,'r',encoding='utf-8') as f:
        data=f.read()
        data=data.split('\n')
    return data
if __name__ == '__main__':
    data1=read2('D:\\大二下\\数据科学\\带作业\\all1.txt')
    data2 = read2('D:\\大二下\\数据科学\\带作业\\all2.txt')
    data11=read('D:\\大二下\\数据科学\\带作业\\抖音数据\\抖音数据\\all.csv')
    data22=read('D:\\大二下\\数据科学\\带作业\\抖音数据\\抖音数据\\all76.csv')
    arrage=[]
    answer=[]
    for i in range(data1.__len__()):
        arrage.append([1,i,int(data1[i])])
    for i in range(data2.__len__()):
        arrage.append([2,i,int(data2[i])])
    for i in range(arrage.__len__()-1):
        for j in range(i+1,arrage.__len__()):
            if arrage[i][2]>arrage[j][2]:
                temp=arrage[i]
                arrage[i]=arrage[j]
                arrage[j]=temp
    for i in range(arrage.__len__()):
        if arrage[i][0]==1:
            answer.append(data11[arrage[i][2]-1])
        else:
            answer.append(data22[arrage[i][2]-1])
    write('D:\\大二下\\数据科学\\带作业\\表格.txt',answer)


